import { Post, Get, Download, Upload, DownloadBlob } from '@/hooks/useRequest';

type ListParams = {
  page: number;
  pageSize: number;
};

type User = {
  username: string;
  password: string;
  mobile: string;
  storeId: number;
};

type Store = {
  endTime: string;
  status: number;
  storeAddress: string;
  storeName: string;
};

type Enterprise = {
  enterpriseAddress: string;
  enterpriseName: string;
  enterprisePhone: string;
  enterpriseType: string;
};

const GlobalAPI = {
  login: Post<{ username: string; password: string }>('/v1/login', { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }),
  queryAllStoreList: Get<any>('/v1/admin/findStoreAll'),
  uploadFile: Upload<any>('/v1/goods/upload'),
  // uploadFile: Upload<any>('/global/uploadFile'),
  removeFile: Post<{ path: string }>('/global/removeFile'),
  getUserInfo: Get<any>('v1/admin/getLoginAdmin'),
  orderSocketServer: 'ws://192.168.0.110:1000/v1/order/websocket/server'
};

const UserAPI = {
  queryUserList: Post<ListParams>('/v1/admin/findAdminList'),
  addUserByAdmin: Post<User>('/v1/admin/registerByAdmin'),
  deleteUser: Post<{ id: number }>('/v1/admin/adminDel'),
  updateUser: Post<User>('/v1/admin/updateAdmin'),
  queryComplaintList: Post<ListParams>('/v1/admin/complaintPageList'),
  auditComplaint: Get<{ complaintId: number }>('/v1/admin/complaintAudit'),
  examineUser: Post<{ id: number; storeId: number }>('/v1/admin/adminCheck')
};

const GoodsAPI = {
  queryGoodsList: Post<ListParams>('/v1/goods/findGoodsByPageCondition'),
  updateGoods: Post<any>('/v1/goods/updateGoods'),
  addGoods: Post<any>('/v1/goods/addGoods'),
  delGoods: Post<{ id: number }>('/v1/goods/delGoods'),
  updateStatus: Post<{ goodsId: string }>('/v1/goods/updateStatus'),
  queryCategoryList: Get<any>('/v1/goods/findGoodsCategory'),
  queryAllGoodsByCate: Get<{ cateId: number }>('/v1/goods/cateFindAllGoods'),
  addCategory: Post<{ cateName: string }>('/v1/goods/addGoodsCategory'),
  updateCategory: Post<{ id: number; cateName: string }>('/v1/goods/updateGoodsCategory'),
  deleteCategory: Get<{ goodsCateId: number }>('/v1/goods/delGoodsCategory'),
  sortCategory: Post<any>('/v1/goods/sortCategory'),
  queryAllGoodsForCate: Post<ListParams>('/v1/goods/findAllGoodsForCate'),
  addGoodsToCate: Post<{ cateId: number; goodsId: number[] }>('/v1/goods/cateAddGoods'),
  delGoodsFromCate: Get<{ cateId: number; goodsId: number }>('/v1/goods/cateDelGoods'),
  goodsOptionsAdd: Post<any>('/v1/goods/goodsOptionsAdd'),
  goodsOptionsFind: Get<{ goodsId: number }>('/v1/goods/goodsOptionsFind'),
  goodsReco: Get<{ goodsId: number }>('/v1/admin/config/setFoodReco')
};

const EnterpriseAPI = {
  queryEnterpriseList: Post<ListParams>('/v1/store/findEnterPriseByPageCondition'),
  queryStaffList: Post<ListParams>('/v1/store/findWorkerInfos'),
  addEnterprise: Post<any>('/v1/store/saveEnterPrise'),
  updateEnterprise: Post<any>('/v1/store/updateEnterPrise'),
  deleteEnterprise: Get<{ enterpriseId: number }>('/v1/store/delEnterPrise'),
  downloadStaffTemplate: Download('/v1/store/getEnterPriseReportTemplate'),
  uploadStaffTemplate: Upload<{ enterpriseId: number }>('/v1/store/importEnterPriseInfoReport'),
  downloadOrder: DownloadBlob('/v1/admin/config/downloadOrder')
};

const OrderAPI = {
  queryOrderList: Post<ListParams>('/v1/order/findOrderPageCondition'),
  updateOrder: Get<{ id: string }>('/v1/order/updateOrderStatus'),
  queryInvoice: Post<any>('/v1/admin/config/getInvoice'),
  handleInvoice: Get<any>('/v1/admin/config/updateInvoice')
};

const StoreAPI = {
  queryStoreList: Post<ListParams>('/v1/store/findByPageCondition'),
  addStore: Post<any>('/v1/store/add'),
  updateStore: Post<any>('/v1/store/update'),
  deleteStore: Post<{ id: number }>('/v1/store/del')
};

const HealthAPI = {
  queryList: Post<any>('/v1/admin/config/getHealth'),
  add: Post<any>('/v1/admin/config/setHealth'),
  upload: Upload('/v1/admin/config/importSport'),
  download: Download('/v1/admin/config/downloadSportTemplate')
};

const MiniConfigAPI = {
  queryCarouselList: Post<any>('/v1/admin/config/getCfgList'),
  queryAllGoods: Get<any>('/v1/goods/findAllGoods'),
  queryAdList: Get<any>('/v1/admin/config/getAd'),
  setCarousel: Post<any>('/v1/admin/config/setCfg'),
  setAd: Post<any>('/v1/admin/config/setAd'),
  delCarsousel: Post<any>('/v1/admin/config/deleteCfg'),
  delAd: Get<any>('/v1/admin/config/deleteAd'),
  saveSetting: Post<any>('/v1/admin/config/setSendBoxCost'),
  getSetting: Post<any>('/v1/admin/config/getSendBoxCost'),
  getImagetext:Get<any>('v1/admin/imagetext/list'),
  deleteImageText:Get<any>('v1/admin/imagetext/removeById'),
  addImageText:Post<any>('/v1/admin/imagetext/add')
};

export { GlobalAPI, UserAPI, GoodsAPI, EnterpriseAPI, StoreAPI, OrderAPI, HealthAPI, MiniConfigAPI };
